package com.stormrage.edu.dao.edu.view.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.edu.view.EduMajorModuleDao;
import com.stormrage.entity.edu.view.EduMajorModule;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @author www.stormragetech.com
 * @date 2016年1月19日
 * @version 1.0.0
 */
@Repository
public class EduMajorModuleDaoImpl extends MysBaseDao implements EduMajorModuleDao {

	private static final Logger logger = LoggerFactory.getLogger(EduMajorModuleDaoImpl.class);

	@Override
	public Integer create(final EduMajorModule arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 Create 】- 开始运行 ");

		final String query = "INSERT INTO edu_major_module (major_id, module_id) VALUES (:majorId, :moduleId)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 Create 】- 完成运行 ");
		return index;
	}

	@Override
	public void deleteById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 DeleteById 】- 开始运行 ");

		final String query = "DELETE FROM edu_major_module WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 DeleteById 】- 完成运行 ");

	}

	@Override
	public void deleteByMajorId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 DeleteByMajorId 】- 开始运行 ");

		final String query = "DELETE FROM edu_major_module WHERE major_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 DeleteByMajorId 】- 完成运行 ");

	}

	@Override
	public void deleteByModuleId(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 DeleteByModuleId 】- 开始运行 ");

		final String query = "DELETE FROM edu_major_module WHERE module_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);
		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 DeleteByModuleId 】- 完成运行 ");

	}

	@Override
	public Integer queryCountById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 queryCountById 】- 开始运行 ");

		final String query = "SELECT COUNT(*) FROM edu_major_module WHERE major_id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		Integer count = queryCount(query, map);

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 queryCountById 】- 完成运行 ");
		return count;
	}

	@Override
	public EduMajorModule queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 queryById 】- 开始运行 ");

		final String query = "SELECT * FROM edu_major_module WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		EduMajorModule entity = queryObject(query, EduMajorModule.class, map);

		logger.debug(" 【 Dao 】- 【 EduMajorModuleDao 】- 【 queryById 】- 完成运行 ");
		return entity;
	}

}
